<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
  <style type="text/css">
    td input
    {
        border-radius: 5px;padding: 4px 5px;border: 1px solid #b6b6b6;
    }
    .link_img
    {
        padding:0px;text-align: center;
    }
    .link_img img
    {
        height: 30px;
    }
    .show_order
    {
        width: 50px;text-align: center;
    }
    #tooltip{
      position:absolute;
      border:1px solid #ccc;
      background:#333;
      padding:2px;
      display:none;
      color:#fff;
    }
  </style>
</head>
<body style="padding:10px;">
  <div class="tplay-body-div">
    <div class="layui-tab">
      <ul class="layui-tab-title">
        <li class="layui-this">分类管理</li>
        <li><a href="{:url('admin/aboutcate/publish')}" class="a_menu">新增分类</a></li>
      </ul>
    </div>
    <table class="layui-table" lay-size="sm">
      <colgroup>
        <col width="50">
        <col width="50">
        <col >
        <!-- <col width="500"> -->
        <col width="200">
        <col width="100">
      </colgroup>
      <thead>
        <tr>
          <th>编号</th>
          <th>排序</th>
          <th>名称</th>
          <!-- <th>描述</th> -->
          <th>创建时间</th>
          <th>操作</th>
        </tr> 
      </thead>
      <tbody>
        {volist name="cates" id="vo"}
        <tr>
          <td>{$vo.id}</td>
          
          <td>
            <input type="text" value="{$vo.sort}" onblur="changeTableVal('about_cate','id','{$vo.id}','sort',this,'text')">
          </td>
          <td><span style="font-weight:500;">{$vo.str}</span>{$vo.name}</td>
          <!-- <td>{$vo.description}</td> -->
          <td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
          <td class="operation-menu">
            <div class="layui-btn-group">
              <a href="{:url('admin/aboutcate/publish',['id'=>$vo.id])}" class="layui-btn layui-btn-xs a_menu layui-btn-primary" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
              <a href="{:url('admin/aboutcate/publish',['pid'=>$vo.id])}" class="layui-btn layui-btn-xs a_menu layui-btn-primary" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
              <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary delete" id="{$vo.id}" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
            </div>
          </td>
        </tr>
        {/volist}
      </tbody>
    </table>
            
    {include file="public/foot"}
    <script type="text/javascript">

    $('.is_top').click(function(){
      var val = $(this).attr('data-val');
      var id = $(this).attr('data-id');
      var i = $(this).find('i');
      var the = $(this);
      if(val == 1){
        var is_top = 0;
      } else {
        var is_top = 1;
      }
      $.ajax({
        type:"post",
        url:"{:url('admin/aboutcate/is_top')}",
        data:{is_top:is_top,id:id},
        success:function(res){
          
          if(res.code == 1) {
            top();
          } else {
            layer.msg(res.msg);
          }
        }
      })

      
      function top(){
        if(val == 1){
          i.attr("class","fa fa-toggle-off");
          the.attr('data-val',0);
        } else {
          i.attr("class","fa fa-toggle-on");
          the.attr('data-val',1);
        }
      }

    })


    $('.delete').click(function(){
      var id = $(this).attr('id');
      layer.confirm('确定要删除?', function(index) {
        $.ajax({
          url:"{:url('admin/aboutcate/delete')}",
          data:{id:id},
          success:function(res) {
            layer.msg(res.msg);
            if(res.code == 1) {
              setTimeout(function(){
                location.href = res.url;
              },1500)
            }
          }
        })
      })
    })
    function changeTableVal(table,id_name,id_value,field,obj,is_where)
    { 
        var value = $(obj).val();
        $.ajax({
            url:"{:url('admin/aboutcate/sort')}",
            data:{'table':table,'id_name':id_name,'id_value':id_value,'field':field,'value':value},
            type:'post',
            async: false,
            dateTyoe:"json",
            success:function(res) {
              layer.msg(res.msg);
            }
        });
      }
    </script>
  </div>
</body>
</html>
